# rox-filer
# Builds from https://github.com/puppylinux-woof-CE/petbuilds
# requires shared-mime-info

. ../../func
. ../../build.conf

URL=https://github.com/woodenshoe-wi/rox-filer/archive/
PKG=rox-filer
VER=woodenshoe-4
COMP=tar.gz
DESC="Light weight gtk file manager"
DEPS=+gtk+2
CAT=Filesystem
DESKTOP=ROX-Filer-file-manager.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)	
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not	

ARCH=$(uname -m)
case $ARCH in
 *64) 	LIBDIR=$LIBCONF64 ;;
 arm*)	LIBDIR=$LIBCONFarm;;
 *) 	LIBDIR=$LIBCONF32 ;;
esac


build() {
	mv ${PKG}-${PKG}-${VER} ${PKG}
	cd ${PKG}
	#./ROX-Filer/AppRun
	#[ "$?" -eq 0 ] || exit 1

	APP_DIR=$(realpath ROX-Filer)
	if [ ! -x "$APP_DIR/src/configure" ]; then
		echo "No 'configure' script! Trying to run autoconf..."
		(cd "$APP_DIR/src"; autoconf)
	fi
	BUILDDIR="$APP_DIR/build"
	[ ! -d "$BUILDDIR" ] && mkdir "$BUILDDIR"
		rm -f "$BUILDDIR/config.cache"
		rm -f "$APP_DIR/src/config.h"	# (for upgrading)
		cd "$BUILDDIR" && "$APP_DIR/src/configure" "$@" \
			&& $MAKE clean && $MAKE && echo Done >&2

	cd ${CWD}
	EXEC=`find ./${PKG}/ROX-Filer -type f -name 'ROX-Filer'`
	if [ "$EXEC" ];then 
		strip --strip-unneeded $EXEC
		cp -arf rox-filer-template ${PKG}-${VER}-${ARCH}_${BUILD}

		cp -arf ${PKG}/ROX-Filer/Help ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -arf ${PKG}/ROX-Filer/images  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -arf ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/AppInfo.xml ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/AppRun ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/.DirIcon ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/Options.xml ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/style.css ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/subclasses ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/Templates.glade ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		cp -af ${PKG}/ROX-Filer/Templates.ui ${PKG}/ROX-Filer/ROX  ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/

		cp -af $EXEC ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/
		chmod 755 ${PKG}-${VER}-${ARCH}_${BUILD}/usr/local/apps/ROX-Filer/ROX-Filer
	else
		exit 1
	fi
	
	rm -r $PKG #clean up
}
	
package() {
	## add this recipe
	#install -d -m 0755 ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/src/dev
	#cat ${PKG}.petbuild > ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/src/dev/$PKG-build-recipe
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/applications
		cat $DESKTOP > ./${PKG}-${VER}-${ARCH}_${BUILD}/usr/share/applications/$DESKTOP
	fi
	# delete any icon cache or library cache
	find ./${PKG}-${VER}-${ARCH}_${BUILD} -type f -name '*cache' -delete
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./${PKG}-${VER}-${ARCH}_${BUILD}/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./${PKG}-${VER}-${ARCH}_${BUILD}/
	### AT THIS POINT you could add custom puppypin or mime types/icons ###
	for p in `ls|grep "\-${ARCH}"|grep -v "files$"` ; do
		case $p in
			*_DEV*) DESC="$PKG development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="$PKG documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="$PKG locales"; DEPS=+${PKG} ;;
		esac	
		echo "packaging $p"	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c=$CAT -p=${p} 2>&1 >/dev/null
		rm -r $p
		mv ${p}.pet ${z0pets_out}
	done
	rm -r ${PKG}-${VER} 2>/dev/null
	rm *.files 2>/dev/null
	echo "done!"
}

# main
retrieve ${PKG}-${VER}.${COMP}
extract ${PKG}-${VER}.${COMP}
build
package	
